'''
Created on Dec 8, 2009

@author: mkiyer
'''

from optparse import OptionParser
from veggie.io.bed import bed_reader
import sys
from veggie.genome.chrom import HG18

if __name__ == '__main__':
    optionparser = OptionParser("usage: %prog [options] infile outfile")
    (options, args) = optionparser.parse_args()
    if len(args) == 0:
        optionparser.error("Must specify an input BED file")
        
    infile = args[0]
    if len(args) == 1:
        outfile = sys.stdout
    else:
        outfile = open(args[1], 'w')

    ucsc_references = HG18.chrom_sizes
    for b in bed_reader(open(infile), track_lines=True):
        if b.is_track_line:
            outfile.write('%s' % b.line)
            continue
        if b.chrom not in ucsc_references:
            continue
        outfile.write("%s\n" % b)
